package com.eqxiu.ieditor.api.impl.mall;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.eqxiu.ieditor.api.mall.IMallCategoryServiceApi;
import com.eqxiu.ieditor.commons.dto.BaseResultData;
import com.eqxiu.ieditor.commons.dto.IdDTO;
import com.eqxiu.ieditor.commons.web.ResultData;

import eqxiu.mall.product.dto.CategoryDTO;
import eqxiu.mall.product.service.api.CategoryServiceApi;

/**
 * @description 商城-分类service<br/>
 * 本类为重构后的结果，原代码写在CategoryController中
 * @author
 * @modified DuYoulong 重构 
 * @creatTime 2019年4月3日
 * @since 1.0.0
 */
public class MallCategoryServiceApiImpl implements IMallCategoryServiceApi, BaseResultData {

	private final Logger logger = LoggerFactory.getLogger(MallCategoryServiceApiImpl.class);

	@Autowired
	private CategoryServiceApi categoryServiceApi;

	/*@ApiOperation(value = "根据分类id获取子分类")
	@GetMapping("/api/category/{cateId}")
	public ResultData categoryList(@PathVariable Integer cateId) {
		List<CategoryDTO> categories = categoryService.getChildList(cateId);
		return success().setList(categories);
	}*/

	@Override
	public ResultData getListByCategoryId(IdDTO dto) {
		try {
			List<CategoryDTO> categoryList = categoryServiceApi.getChildList(dto.getId());
			return success().setList(categoryList);
		} catch (Exception e) {
			logger.error("根据分类id获取子分类异常={}", e);
			return fail();
		}
	}

}
